﻿using System;
using wojilu.ORM;
using wojilu.Web.Mvc;

namespace wojilu.Apps.Qycms.Domain
{
    [Table("ybb_document")]
    [Serializable]
    public class Document : ObjectBase<Document>
    {

        [Default("cn"), Column(Length = 50)]
        public String lng { get; set; }

        [Default(50), Column(Length = 6)]
        public Int32 pid { get; set; }

        [Default(0), Column(Length = 6)]
        public Int64 mid { get; set; }

        [Default(0), Column(Length = 6)]
        public Int32 aid { get; set; }

        [Default(0), Column(Length = 11)]
        public Int64 tid { get; set; }

        [Column(Length = 200)]
        public String extid { get; set; }

        [Default(0), Column(Length = 11)]
        public Int32 sid { get; set; }

        [Default(0), Column(Length = 8)]
        public Int32 fgid { get; set; }

        [Column(Length = 100)]
        public String linkdid { get; set; }

        [TinyInt, Default(1), Column(Length = 1)]
        public Int32 isclass { get; set; }

        [TinyInt, Default(0), Column(Length = 1)]
        public Int32 islink { get; set; }

        [TinyInt, Default(1), Column(Length = 1)]
        public Int32 ishtml { get; set; }

        [TinyInt, Default(1), Column(Length = 1)]
        public Int32 ismess { get; set; }

        [TinyInt, Default(0), Column(Length = 1)]
        public Int32 isorder { get; set; }

        [Default(0), Column(Length = 6)]
        public Int32 ktid { get; set; }

        [TinyInt, Default(0), Column(Length = 1)]
        public Int32 purview { get; set; }

        [TinyInt, Default(0), Column(Length = 1)]
        public Int32 istemplates { get; set; }

        [TinyInt, Default(0), Column(Length = 1)]
        public Int32 isbase { get; set; }

        [Column(Length = 100)]
        public String recommend { get; set; }

        [Default(""), Column(Length = 50)]
        public String tsn { get; set; }

        [Column(Length = 200)]
        public String title { get; set; }

        [Column(Length = 200)]
        public String longtitle { get; set; }

        [Column(Length = 8)]
        public String color { get; set; }

        [Column(Length = 20)]
        public String author { get; set; }

        [Column(Length = 30)]
        public String source { get; set; }

        [Column(Length = 200)]
        public String pic { get; set; }

        [Column(Length = 250)]
        public String tags { get; set; }

        [Column(Length = 200)]
        public String headtitle { get; set; }

        [Default(""), Column(Length = 220)]
        public String keywords { get; set; }

        [LongText]
        public String description { get; set; }

        [LongText]
        public String summary { get; set; }

        [Column(Length = 250)]
        public String link { get; set; }

        [Money, Default(0.00)]
        public Decimal oprice { get; set; }

        [Money, Default(0.00)]
        public Decimal bprice { get; set; }

        [Default(0), Column(Length = 6)]
        public Int32 click { get; set; }

        [NotNull("")]
        public DateTime addtime { get; set; }

        [NotNull("")]
        public DateTime uptime { get; set; }

        [Column(Length = 100)]
        public String template { get; set; }

        [Column(Length = 100)]
        public String filename { get; set; }

        [Column(Length = 100)]
        public String filepath { get; set; }

        [Default(0), Column(Length = 3)]
        public Int32 filepage { get; set; }

        [NotSave]
        public String readlink
        {
            get
            {
                Configs config = Configs.find("valname=:v").set("v", "is_html").first();
                var is_html = config.value;
                //if (is_html == "0")
                //{
                //    if (islink == 1)
                //    {
                //        return link;
                //    }
                //    else
                //    {
                //        return strUtil.Join(sys.Path.Root, "Article/Read/" + Id);
                //    }
                //}
                //else
                //{
                //    return String.Empty;
                //}
                if (islink == 1)
                {
                    return link;
                }
                else
                {
                    return strUtil.Join(sys.Path.Root, "Article/Read/" + Id + MvcConfig.Instance.UrlExt);
                }
            }
        }

        [NotSave]
        public String readwaplink
        {
            get
            {
                Configs config = Configs.find("valname=:v").set("v", "is_html").first();
                var is_html = config.value;
                //if (is_html == "0")
                //{
                //    if (islink == 1)
                //    {
                //        return link;
                //    }
                //    else
                //    {
                //        return strUtil.Join(sys.Path.Root, "Wap/Article/Read/" + Id);
                //    }
                //}
                //else
                //{
                //    return String.Empty;
                //}
                if (islink == 1)
                {
                    return link;
                }
                else
                {
                    return strUtil.Join(sys.Path.Root, "Wap/Article/Read/" + Id + MvcConfig.Instance.UrlExt);
                }
            }
        }

        [NotSave]
        public String typename
        {
            get
            {
                var t = TypeList.findById(tid);
                if (t == null) return string.Empty;
                return t.typename;
            }
        }

        [NotSave]
        public String content
        {
            get
            {
                Document_Content dc = Document_Content.find(" did = " + Id).first();
                if (dc == null) return String.Empty;
                return dc.content;
            }
        }

        [NotSave]
        public String wapcontent
        {
            get
            {
                Document_Content dc = Document_Content.find(" did = " + Id).first();
                if (dc == null) return String.Empty;
                return dc.wapcontent;
            }
        }
    }
}
